package com.wxd.controller;


import com.sun.javafx.collections.MappingChange;
import com.wxd.entity.Laboratory;
import com.wxd.service.LaboratoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxd
 * @since 2022-03-08
 */
@RestController
@RequestMapping("/laboratory")
public class LaboratoryController {
    @Resource private LaboratoryService ls;
    @GetMapping("/selectAll")
    public Map<String,Object> selectAll(){
        List<Laboratory> list = ls.list();
        return  new HashMap<String, Object>(){{
            put("status","success");
            put("list",list);
        }};
    }
    @PostMapping("/addLab")
    public Map<String,Object> addLab(@RequestBody Laboratory laboratory){
        ls.save(laboratory);
        return new HashMap<String, Object>(){{
            put("status","success");
        }};
    }
    @PutMapping("/updateLab")
    public Map<String, Object> updateLab(@RequestBody Laboratory laboratory){
        ls.updateById(laboratory);
        return new HashMap<String, Object>(){{
            put("status","success");
        }};
    }
    @DeleteMapping("/deleteById/{id}")
    public Map<String, Object> deleteById(@PathVariable("id") int id){
        ls.removeById(id);
        return new HashMap<String, Object>(){{
            put("status","success");
        }};
    }
}

